﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using FranceTriple.Dal;

namespace TeamFranceTriple
{
    public partial class ucForumSearch : BaseUserControl
    {
        private String forumsearchLocalized = "forumsearch".ToLocalizedString();
        
        public String Keywords
        {
            get { return KeywordTextBox.Text; }
        }

        public String[] Authors
        {
            get
            {
                List<String> AuthorsList = new List<String>();
                foreach (ListItem authorItem in AuthorCheckBoxList.Items)
                {
                    if (authorItem.Selected)
                        AuthorsList.Add(authorItem.Text);
                }
                return AuthorsList.ToArray();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //Button1.PostBackUrl = "~/" + ThisMaster.RequesterCulture +"/topic/search";
            this.Page.Title = String.Format("{0}{1}", prefixTitle, forumsearchLocalized);

            AuthorCheckBoxList.DataSource = ForumPostDal.GetAuthors((Session["AnonymousID"] == null) ? String.Empty : Session["AnonymousID"].ToString());
            AuthorCheckBoxList.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var criteria = new ForumSearchCriteria();
            criteria.Authors = this.Authors;
            criteria.Keywords = this.Keywords;
            Session["criteria"] = criteria;
            Response.Redirect("~/" + ThisMaster.Requester.Culture + "/topic/search");
        }
    }
}